package com.market.controller.wx;

import com.market.bean.MarketUser;
import com.market.bean.common.BaseRespVo;
import com.market.bean.common.CommonData;
import com.market.bean.vo.wx.WxIndexBo;
import com.market.bean.vo.wx.WxOrderListVo;
import com.market.service.wx.WxOrderService;
import com.market.service.wx.WxUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author fan
 * @Description:
 * @since 2023/01/02 21:13
 */
@RestController
@RequestMapping("wx/user")
public class WxUserController {
    @Autowired
    WxUserService userService;
    @Autowired
    WxOrderService orderService;

    @GetMapping("index")
    public BaseRespVo<WxIndexBo> index() {

        Subject subject = SecurityUtils.getSubject();
        MarketUser marketUser = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
        Integer id = marketUser.getId();
        // Integer id=1;
        CommonData<WxOrderListVo> list1 = orderService.list(((short) 1), null, null, id);
        CommonData<WxOrderListVo> list2 = orderService.list(((short) 2), null, null, id);
        CommonData<WxOrderListVo> list3 = orderService.list(((short) 3), null, null, id);
        CommonData<WxOrderListVo> list4 = orderService.list(((short) 4), null, null, id);
        WxIndexBo data = new WxIndexBo(list3.getTotal(),list4.getTotal(),list1.getTotal(),list2.getTotal());
        return BaseRespVo.ok(data);
    }
}
